package com.danbay.cloud.auth.service;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @author SJG
 *         2017/12/20.
 */
@RestController
@RequestMapping("/")
public class UserController {

    @GetMapping(value = "/current")
    public Principal getUser(Principal principal) {
        if (principal!=null && principal.equals(SecurityContextHolder.getContext().getAuthentication())) {
            return principal;
        }
        return null;
    }
}